from flask import Blueprint, jsonify,render_template,jsonify
from common.filter import filter_url
from db import get_db

queryServer = Blueprint('queryServer', __name__)

def fetchsql(sql):
    connection = get_db()
    cursor = connection.cursor()
    cursor.execute(sql)
    rows = cursor.fetchall()
    connection.commit()
    return rows

# 纯sql查询
@filter_url(url='name')
@queryServer.route("/name")
def name():
    return "query"

@queryServer.route("/template")
@filter_url(url='template')
def template():
    return render_template("query/index.html",s1='第一个template')

@queryServer.route("/china")
def china():
    sql = '''
select * from 山东省
    '''
    rows = fetchsql(sql)
    return jsonify({"success": True,"data": rows}) 